package com.awenhui.demo.dao;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * @author yuxf
 * @version 1.0
 * @date 2021/3/2 10:24
 */
@Component
public class SuperMapper {

    @Autowired
    SuperMapperInternal superMapperInternal;


    /**
     * 查询实体
     * @param entity 实体条件
     * @param clazz 实体类型
     * @param <T>
     * @return
     * @throws JsonProcessingException
     */
    public <T> T select(T entity, Class<T> clazz) throws JsonProcessingException {
        HashMap<String, Object> mapResult = superMapperInternal.select(entity);
        ObjectMapper objectMapper = new ObjectMapper();
        String json = objectMapper.writeValueAsString(mapResult);
        T t = objectMapper.readValue(json, clazz);
        return t;
    }

}
